package com.supor.aiot.md_msg.adapter;

import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.android.baseconfig.base.GlideApp;
import com.android.baseconfig.base.GlideRequest;
import com.android.baseconfig.common.views.CircleImageView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.supor.aiot.common.helper.GlobalDataCache;
import com.supor.aiot.common.utils.NotNullUtils;
import com.supor.aiot.md_msg.R;
import com.supor.aiot.md_msg.entity.MsgCenterListBean;
import com.supor.aiot.md_msg.entity.MsgCenterListResultBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @author: zook
 * @date: 2021/10/14
 */
public class MsgListAdapter extends BaseQuickAdapter<MsgCenterListBean, BaseViewHolder> {
    public MsgListAdapter() {
        super(R.layout.item_msg_notic, new ArrayList<>());
        addChildClickViewIds(R.id.ll_content, R.id.ll_right_del);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, MsgCenterListBean item) {
        baseViewHolder.setText(R.id.tv_msg_title, NotNullUtils.getNotNullValue(item.getMessageTitle()))
                .setText(R.id.tv_msg_content, NotNullUtils.getNotNullValue(item.getMessageContent()))
                .setGone(R.id.view_unread, "1".equals(item.getIsRead()))
        ;
//        try {
//            SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//            baseViewHolder.setText(R.id.tv_msg_date, format.format(item.getCreateTime()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
        try {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            SimpleDateFormat format2 = new SimpleDateFormat("yyyy年MM月dd日 HH:mm");
            Date date = format.parse(item.getCreateTime());
            baseViewHolder.setText(R.id.tv_msg_date, NotNullUtils.getNotNullValue(format2.format(date)));
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (null != item.getAddrJson()) {
            switch (NotNullUtils.getNotNullValue(item.getAddrJson().getType())) {
                case "COOKINGFINISH"://烹饪完成
                    GlideApp.with(getContext()).load(R.mipmap.ic_msg_cooking_comp).into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));
                    break;
                case "DEVICEBIND"://绑定设备
                    GlideApp.with(getContext()).load(R.mipmap.ic_msg_bind_devices).into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));
                    break;
                case "LOGINAPP"://登录app
                    GlideApp.with(getContext()).load(R.mipmap.ic_msg_login).into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));
                    break;
                case "DEVICEUNBIND"://解绑设备
                    GlideApp.with(getContext()).load(R.mipmap.ic_msg_unbind_devices).into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));
                    break;
                case "NEWRECIPE"://食谱上新
                    GlideApp.with(getContext()).load(R.mipmap.ic_msg_new_recipe).into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));
                    break;
            }
        }

//        GlideApp.with(getContext())
//                .load(item.getRemark())
//                .into((CircleImageView) baseViewHolder.getView(R.id.iv_ava));

//
//        这都是系统消息类型：
//        bossTUserMessage/page?messageType=SYSTEM
//
//        具体细分还是根据addrJson参数：
//        {"typeId":"SY-50MT10","type":"COOKINGFINISH","isJump":1}//烹饪完成
//        {"typeId":"SY-50MT01","type":"DEVICEBIND","isJump":1}//绑定设备
//        {"type":"LOGINAPP","isJump":0}//登录app
//        {"type":"DEVICEUNBIND","isJump":0}//解绑设备
//        isJump=1跳转；typeId:跳转需要的参数；type:类型

    }
}
